package com.neusoft.neu24.controller;


import com.neusoft.neu24.Result.CommonResult;
import com.neusoft.neu24.entity.Role;
import com.neusoft.neu24.service.impl.RoleServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private RoleServiceImpl roleService;

    @GetMapping("/sysnode/load/{rid}")
    public CommonResult<List<Integer>> loadById(@PathVariable Integer rid) {
        return roleService.loadById(rid);
    }

    @PutMapping("/sysnode/auth/{rid}")
    public CommonResult<List<Integer>> authEditById(@PathVariable("rid") Integer rid, @RequestBody List<Integer> sids) {
        System.out.println(rid+ "  "+ sids);
        return roleService.authEditById(rid, sids);
    }

    @GetMapping("/list")
    public CommonResult<List<Role>> listAll(){
        return roleService.listAll();
    }

    @PostMapping("/add")
    public CommonResult<Integer> add(@RequestBody Role role) { return roleService.add(role);
    }

    @PostMapping("/delete")
    public CommonResult<Integer> delete(@RequestBody Role role) {
        return roleService.deleteById(role);
    }

    @PutMapping("/edit")
    public CommonResult<Integer> editById(@RequestBody Role role) {
        return roleService.editById(role);
    }
    }
